//
//  ProductImgOtherCell.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/16.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "ProductImgOtherCell.h"
#import "CommonMacro.h"
#import "ProductImgOtherModel.h"
#import "UIImageView+WebCache.h"

@interface ProductImgOtherCell ()
@property (nonatomic,strong) UIImageView *productImageView ;
@property (nonatomic,strong) UIImageView *smallImageView;
@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UILabel *specificationsLabel;
@property (nonatomic,strong) UILabel *fitAgeLabel;
@property (nonatomic,strong) UILabel *priceLabel;
@property (nonatomic,strong) UILabel *stockLabel;
@property (nonatomic,strong) UILabel *lastNumLabel;

@end

@implementation ProductImgOtherCell

- (void)awakeFromNib {
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initWithSubviews];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    [self valueWithSubview];
}

- (void)initWithSubviews
{
    
    
    //1.产品图片 中
    self.productImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5,3, self.frame.size.width*0.35, 120)];
    [self addSubview:self.productImageView];
    
    //2.坐标
    CGFloat titleX = self.productImageView.frame.origin.x+self.productImageView.frame.size.width+3;
    CGFloat titleY = self.productImageView.frame.origin.y;
    CGFloat titleW = SCREEN_WIDTH*0.6;
    CGFloat titleH = 40;
    CGFloat labelH = 20;
    
    //3.添加商品小样图片
//    for (int i=0; i<2; i++) {
//        self.smallImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0+i*self.productImageView.frame.size.width*0.2,self.productImageView.size.height*1.65, self.frame.size.width*0.15, self.frame.size.height*0.15)];
//        self.smallImageView.backgroundColor = [UIColor blueColor];
//        [self addSubview:self.smallImageView];
//    }
    
    //3.1产品具体介绍
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleX, titleY, titleW, titleH)];
//    self.titleLabel.backgroundColor = [UIColor grayColor];
    self.titleLabel.textColor = UIColorWithRGBA(116, 116, 116, 1);
    
    self.titleLabel.font = [UIFont fontWithName:nil size:15];
    [self addSubview:self.titleLabel];
    
    //3.2 Specifications规格
    self.specificationsLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleX, titleH+titleY,titleW*0.5,labelH)];
//    self.specificationsLabel.backgroundColor = [UIColor redColor];
    self.specificationsLabel.textColor = UIColorWithRGBA(171, 171, 171, 1);
    [self.specificationsLabel setFont:[UIFont systemFontOfSize:14]];
    [self addSubview:self.specificationsLabel];
    
    //3.3适用年龄
    self.fitAgeLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleX, self.specificationsLabel.frame.size.height+self.specificationsLabel.frame.origin.y, titleW*0.7, labelH)];
    self.fitAgeLabel.textColor = UIColorWithRGBA(171, 171, 171, 1);
    [self.fitAgeLabel setFont:[UIFont systemFontOfSize:14]];
    //    fitAgeLabel.backgroundColor = [UIColor blueColor];
    [self addSubview:self.fitAgeLabel];
    
    //3.4 价钱
    self.priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.specificationsLabel.frame.size.width+titleX,self.specificationsLabel.frame.origin.y+6, self.fitAgeLabel.frame.size.width*0.7, labelH*1.5)];
    [self.priceLabel setFont:[UIFont systemFontOfSize:22]];
    self.priceLabel.textColor = UIColorWithRGBA(233, 61, 105, 1);
//        self.priceLabel.backgroundColor = [UIColor blueColor];
    self.priceLabel.textAlignment = NSTextAlignmentRight;
    [self addSubview:self.priceLabel];
    
    
    //4.销售量
    self.lastNumLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleX,self.fitAgeLabel.frame.size.height+self.fitAgeLabel.frame.origin.y, self.specificationsLabel.frame.size.width, labelH)];

    self.lastNumLabel.textColor = UIColorWithRGBA(171, 171, 171, 1);
    [self.lastNumLabel setFont:[UIFont systemFontOfSize:14]];
//    self.lastNumLabel.backgroundColor = [UIColor redColor];
    [self addSubview:self.lastNumLabel];
    
    //5.库存
    self.stockLabel = [[UILabel alloc] initWithFrame:CGRectMake(titleX, self.lastNumLabel.frame.size.height+self.lastNumLabel.frame.origin.y, self.fitAgeLabel.frame.size.width, labelH)];
    self.stockLabel.textColor = UIColorWithRGBA(171, 171, 171, 1);
    self.stockLabel.font = [UIFont fontWithName:nil size:14];
    [self addSubview:self.stockLabel];
    
}


- (void)valueWithSubview
{
    [self.productImageView setImageWithURL:[NSURL URLWithString:self.productImgOtherModel.imageURL]];
#warning 服务器暂时没有返回
//    [self.smallImageView setImageWithURL:[NSURL URLWithString:self.productImgOtherModel.imageURL]];
    self.titleLabel.text = self.productImgOtherModel.title;
    self.titleLabel.numberOfLines = 0;
    [self.titleLabel sizeToFit];
    self.specificationsLabel.text = [NSString stringWithFormat:@"规格：%@",self.productImgOtherModel.specification];
    self.fitAgeLabel.text = [NSString stringWithFormat:@"试用年龄：%@",self.productImgOtherModel.useAge];
    self.priceLabel.text = self.productImgOtherModel.price;
    self.stockLabel.text = [NSString stringWithFormat:@"库存：%@",self.productImgOtherModel.stock];
    self.lastNumLabel.text = [NSString stringWithFormat:@"销量：%@",self.productImgOtherModel.amount];
    
}
@end
